home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / BoxMaker++ / µZak ƒ / queue.h < prev    next >
Encoding:
Text File  |  1995-01-20  |  875 b   |  45 lines  |  [TEXT/KAHL]

  1. //
  2. // queue is a template for a queue
  3. //
  4. // This is the simplest of queues, taken directly from
  5. // Knuth, Fundamental algorithms, page 240, but with some changes
  6. //
  7. // Note: this code _assumes_ that class C is a pointer type
  8. // (well, at least that one can do 'C a_C = 0')
  9. //
  10. template<class C> class queue
  11. {
  12.     public:
  13.         queue( unsigned int numItems);
  14.         ~queue();
  15.  
  16.         Boolean isEmpty() const;
  17.         Boolean isFull() const;
  18.         unsigned int Length() const;
  19.         
  20.         void Add( C newItem);
  21.         C Remove();
  22.  
  23.     private:
  24.         const unsigned int size;
  25.         unsigned int F;
  26.         unsigned int R;
  27.         unsigned int numInside;
  28.         C *theItems;
  29. };
  30.  
  31. template<class C> inline Boolean queue<C>::isEmpty() const
  32. {
  33.     return (numInside == 0);
  34. }
  35.  
  36. template<class C> inline Boolean queue<C>::isFull() const
  37. {
  38.     return (numInside == size);
  39. }
  40.  
  41. template<class C> inline unsigned int queue<C>::Length() const
  42. {
  43.     return numInside;
  44. }
  45.